﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EfSandbox.Entities.Final.Eod.Mappings {
    public class SymbolMap :EntityTypeConfiguration<Symbol> {
        
        public SymbolMap() {
            // Table
            ToTable("fin.eod_symbols");

            // Primary Key
            HasKey(s => s.SymbolId);

            // Index
            Property(s => s.ExchangeId)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_SYM_CD", 1) { IsUnique = true }));
            Property(s => s.SymbolCode)
                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute("IX_SYM_CD", 2) { IsUnique = true }));

            // Attributes
            Property(s => s.SymbolId)
                .HasColumnName("sym_id");

            Property(s => s.SymbolCode)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(25)
                .HasColumnName("sym_cd");

            Property(s => s.SymbolName)
                .IsOptional()
                .IsUnicode(false)
                .HasMaxLength(250)
                .HasColumnName("sym_desc");

            Ignore(s => s.SymbolShortLable);

            Ignore(s => s.SymbolLongLable);

            // Reletionships
            // 1:0..n Exchanges
            Property(s => s.ExchangeId)
                .IsRequired()
                .HasColumnName("sym_exc_id");
            HasRequired(s => s.Exchange)
                .WithMany()
                .HasForeignKey(s => s.ExchangeId);

        }
    }
}
